package com.flying.pas.security.service;

import com.flying.common.annotation.DaoCreate;
import com.flying.common.annotation.DaoQuery;
import com.flying.common.annotation.DaoRemove;
import com.flying.common.annotation.DaoUpdate;
import com.flying.common.annotation.Transaction;
import com.flying.common.util.Codes;
import com.flying.framework.annotation.MethodInfo;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.model.ActionResult;
import com.flying.framework.model.QueryResult;
import com.flying.framework.service.AbstractService;
import com.flying.pas.security.model.Perm;
import com.flying.pas.security.model.Role;
import com.flying.pas.security.model.User;

@Service(value="PermService", desc="")
public class PermService extends AbstractService{
	private RolePermService rps;
	
	public void setRolePermService(RolePermService s) {
		this.rps = s;
	}
        
	@MethodInfo("新增")
	@DaoCreate(entity=Perm.ENTITY_NAME)
	public Perm create(
			@Param(value=Perm.MODULE, required=true,	desc="所属模块") String module,
			@Param(value=Perm.NAME, required=true,	desc="权限名称") String name,
			@Param(value=Perm.REMARKS, required=false,	desc="说明") String remarks,
			@Param(value=Perm.TAG, required=false,	desc="标签") String tag
		
		) throws Exception {
		return null;
	}

	@MethodInfo("修改")
	@DaoUpdate(entity=Perm.ENTITY_NAME)
	public ActionResult update(
			@Param(value=Perm.PERM_ID, required=true,	desc="权限ID") Long perm_id,
			@Param(value=Perm.MODULE, required=true,	desc="所属模块") String module,
			@Param(value=Perm.NAME, required=true,	desc="权限名称") String name,
			@Param(value=Perm.REMARKS, required=false,	desc="说明") String remarks,
			@Param(value=Perm.TAG, required=false,	desc="标签") String tag
		) throws Exception {
		return null;
	}

	@MethodInfo("删除")
	@Transaction
	@DaoRemove(entity=Perm.ENTITY_NAME)
	public ActionResult remove(
			@Param(value=Perm.PERM_ID, required=true,	desc="权限ID") Long perm_id
		) throws Exception {
		this.rps.removeByPerm(perm_id);
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Perm.ENTITY_NAME, pageable=true, modelClass=Perm.class)
	public QueryResult<Perm> findAll(
			@Param(value=Perm.MODULE, required=false,	desc="所属模块") String module,
			@Param(value=Perm.NAME, required=false,	desc="权限名称") String name,
			@Param(value=Perm.TAG, required=false,	desc="标签") String tag,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) throws Exception {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Perm.ENTITY_NAME, pageable=false, modelClass=Perm.class)
	public QueryResult<Perm> findByUserId(
			@Param(value=User.USER_ID, 	required=true, desc="用户ID") Long user_id) throws Exception {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Perm.ENTITY_NAME, pageable=false, modelClass=Perm.class)
	public QueryResult<Perm> findByRoleId(
			@Param(value=Role.ROLE_ID, 	required=true, desc="角色ID") Long role_id) throws Exception {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=Perm.ENTITY_NAME, single=true, throwsNotFoundException=true )
	public Perm findById(
			@Param(value=Perm.PERM_ID, required=true,	desc="权限ID") Long perm_id
		) throws Exception {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=Perm.ENTITY_NAME, pageable=false, modelClass=Perm.class )
	public QueryResult<Perm> findByIds(
			@Param(value=Perm.PERM_ID, required=true,	desc="权限IDs", tag="IN") Long[] perm_ids
		) throws Exception {
		return null;
	}

}